package com.longxi.tianjintianbao.ui.adapter.multitype.maintain;

import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.model.assetrepair.AssetRepair;
import com.longxi.tianjintianbao.model.maintain.AssetsMaintain;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class MaintainViewBinder2 extends ItemViewBinder<AssetsMaintain, MaintainViewBinder2.ViewHolder> {
    OnClickListener listener;

    public MaintainViewBinder2(OnClickListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_asset_repair, parent, false);
        return new ViewHolder(root);
    }

    

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull AssetsMaintain assetsMaintain) {
        holder.tvReceiptNumber.setText(
                "资产编号:" + assetsMaintain.getCode() +
                "\n资产名称:" + assetsMaintain.getName() +
                "\n资产分类:" + assetsMaintain.getClassify() +
                "\n运维类型:" + assetsMaintain.getType() +
                "\n运维单位:" + assetsMaintain.getUnit() +
                "\n运维记录:" + assetsMaintain.getRecords() +
                "\n运维内容:" + assetsMaintain.getContent());
        holder.tvState.setText("运维前状态:" + assetsMaintain.getBefotstate() +
                                "\n运维后状态" + assetsMaintain.getEndstate());

        holder.mLlBtn.setOnClickListener(v -> listener.onClick(holder.getAdapterPosition()));
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ConstraintLayout mLlBtn;
        TextView tvReceiptNumber;
        TextView tvState;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            tvReceiptNumber = itemView.findViewById(R.id.tvReceiptNumber);
            tvState = itemView.findViewById(R.id.tvState);
        }
    }

    public interface OnClickListener {
        void onClick(int position);
    }

}
